/**
 * 
 */
package cn.terrence.myrpc.common.nio;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @author wuchuang
 * 2018年1月10日上午11:46:05
 */
public class BIO {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			FileInputStream fin = new FileInputStream(new File("D:\\test.txt"));
			FileChannel fc = fin.getChannel();
			
			FileOutputStream fout = new FileOutputStream(new File("D:\\out.txt"));
			FileChannel fcout = fout.getChannel();

			ByteBuffer buffer = ByteBuffer.allocate(1024);
			
			while(true){
				int EOF = fc.read(buffer);
				if(-1 == EOF){
					break;
				}
				buffer.flip();
				fcout.write(buffer);
				buffer.clear();
			}
			fc.close();
			fcout.close();
			fin.close();
			fout.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

}
